package com.fz.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

/**
 * Created by webrx on 2017/6/27.
 */
@Controller
public class User02 {
  @RequestMapping(value ="save",method = RequestMethod.POST) @ResponseBody
   public void save(HttpServletRequest req){
     String name= req.getParameter("name");
      System.out.println(name);
   }
    @RequestMapping(value = "show02",method = RequestMethod.GET)
   public void show(HttpServletRequest req, HttpServletResponse resp) throws IOException {
       resp.setContentType("text/html;charset=utf-8");
       resp.setContentType("utf-8");
        PrintWriter out = resp.getWriter();
        out.print("nihao ");
   }

   @RequestMapping("/del")
   public ModelAndView del(HttpServletRequest req) throws UnsupportedEncodingException {
    req.setCharacterEncoding("utf-8");
      ModelAndView mv = new ModelAndView("kk");//kk.jsp
        mv.addObject("user",req.getParameter("id"));
        //mv.setViewName("aa");//aa.jsp
        //mv.setViewName("bb");
       System.out.println(req.getParameter("id"));
       return mv;
   }

   @RequestMapping("/user06")
   public String user(Model m){
       m.addAttribute("name","oen");
       m.addAttribute("age",19);
       m.addAttribute("address",new String[]{"网","上"});

       return "user06";
   }

    @RequestMapping(value = "xiao/{id}/{name}")
   public void xiao(@PathVariable("id") int id,@PathVariable("name") String name ,HttpServletResponse resp) throws IOException {
       resp.setCharacterEncoding("utf-8");
       resp.setContentType("text/html;charset=utf-8");
       PrintWriter out = resp.getWriter();
        out.print(id+"="+name);
   }

   @RequestMapping("/add09")
    public void add09(@RequestParam(value = "nn" ,required = false,defaultValue = "小王") String name01,@RequestParam(value = "id",required = true,defaultValue = "99") int idd, HttpServletResponse resp) throws IOException {
       resp.setCharacterEncoding("utf-8");
       resp.setContentType("text/html;charset=utf-8");
       PrintWriter out = resp.getWriter();

       out.print(name01+"***"+idd);

    }

}
